package com.springboot.service.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.springboot.mapper.UserMapper;
import com.springboot.po.User;
import com.springboot.service.UserService;

@Service
public class UserServiceImpl implements UserService{
	@Autowired
	UserMapper userMapper;
	
	@Override
	public int getUserById(String userId) {
		return userMapper.getUserById(userId);
	}

	@Override
	public int saveUser(User user) {
		return userMapper.saveUser(user);
	}
	
	@Override
	public User getUserByIdByPass(User user) {
		// TODO Auto-generated method stub
		return userMapper.getUserByIdByPass(user);
	}

	@Override
	public User findSerect(User user) {
		// TODO Auto-generated method stub
		return userMapper.findSerect(user);
	}

	@Override
	public BigDecimal getPoints(String userId) {
		//查询积分
		return userMapper.getPoints(userId);
	}

	@Override
	public int getMemLevel(String userId) {
		//查询等级
		return userMapper.getMemLevel(userId);
	}

	@Override
	public int spendPoints(String userId, BigDecimal points) {
		//目前拥有积分
		BigDecimal pointsNow = userMapper.getPoints(userId);
		if(pointsNow.compareTo(points) >= 0) {
			//大于才更改
			pointsNow = pointsNow.subtract(points);
			return userMapper.updatePoints(userId, pointsNow);
		}
		return 0;
	}

	@Override
	public BigDecimal getMaxPoints(String userId) {
		return userMapper.getMaxPoints(userId);
	}
		
}
